﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="flv.min.js"></script>
</head>
<body>
    <video muted="muted" webkit-playsinline="true" autoplay="true" id="player"></video>
    <script>
        //ref https://github.com/bilibili/flv.js/issues/498  ✔
        if (flvjs.isSupported()) {
            var player = document.getElementById('player');

            var flvPlayer = flvjs.createPlayer({
                type: 'flv',
                isLive: true,
                //url: "ws://localhost:1818/jt1078live?token=" + Math.floor((Math.random() * 1000000) + 1)
                //isLive: true,
                url: "JT1078_3.flv"
            });

            var width, height, flag;
            flvPlayer.attachMediaElement(player);
            flvPlayer.on(flvjs.Events.SCRIPTDATA_ARRIVED, (e) => {
                console.log(e);
            });
            flvPlayer.load();

            flvPlayer.play();
                        (function componentDidMount() {
                this.cleanBuff = setInterval(function () {
                    let buffered = player.buffered
                    console.log("start...")
                    if (buffered.length > 0) {
                        let end = buffered.end(0)
                        if (end - player.currentTime > 0.15) {
                            player.currentTime = end - 0.1;
                            console.log("exe... start")
                        }
                    }
                    console.log("end...")
                }, 3 * 10 * 1000)
            })();
        }
    </script>
</body>
</html>